﻿using System;
using System.Text;
using System.Web;
using Clipping.Infrastructure.Interfaces;
using Clipping.Infrastructure.Models;

namespace Clipping.SearchUrlConstructors
{
	public class ZhongsouUrlConstructor : ISearchUrlConstruct
	{
		private Encoding _urlEncoding = Encoding.GetEncoding("gb2312");
		public Uri ConstructUrl(Infrastructure.Models.SearchObject searchObj)
		{
			//Contract.Requires(searchObj != null);
			if (searchObj.SearchType == SearchType.SearchInTitle)
			{
				return new Uri(string.Format("{0}{1}{2}", "http://z.zhongsou.com/n?w=", HttpUtility.UrlEncode(searchObj.Keyword, this._urlEncoding), "&t=1"));
			}
			else
			{
				return new Uri(string.Format("{0}{1}{2}", "http://z.zhongsou.com/n?w=", HttpUtility.UrlEncode(searchObj.Keyword, this._urlEncoding), "&t=0"));
			}
		}

		public Uri ConstructAbsoluteUrl(Uri baseUri, string url)
		{
			return UriHelper.ConstructAbsoluteUrl(baseUri, url);
		}
	}
}
